﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;


namespace LambdaToSql.Attribute
{
    /// <summary>
    /// 是否为主键
    /// </summary>
    public class LambdaToSqlAttribute : System.Attribute
    {
        /// <summary>
        /// 是否主键列
        /// </summary>
        public bool IsPrimaryKey { get; set; }

        /// <summary>
        /// 是否标识列
        /// </summary>
        public bool IsIdentity { get; set; }


        //public static LambdaToSqlAttribute GetAttribute(PropertyInfo pi)
        //{
        //    var obj = System.Attribute.GetCustomAttribute(pi, typeof(LambdaToSqlAttribute)) as LambdaToSqlAttribute;
        //    if (obj == null)
        //    {
        //        obj = new LambdaToSqlAttribute() { IsIdentity = false, IsPrimaryKey = false };
        //    }
        //    return obj;
        //}

        ///// <summary>
        ///// 获取主键列
        ///// </summary>
        ///// <typeparam name="T"></typeparam> 
        ///// <returns></returns>
        //public static List<string> GetPrimaryKey<T>() where T : class, new()
        //{
        //    var properties = (new T()).GetType().GetProperties();
        //    var list = GetPrimaryKey(properties);
        //    return list;
        //}

        ///// <summary>
        ///// 获取主键列
        ///// </summary>
        ///// <param name="properties"></param>
        ///// <returns></returns>
        //public static List<string> GetPrimaryKey(PropertyInfo[] properties)
        //{
        //    var list = new List<string>();
        //    foreach (PropertyInfo pi in properties)
        //    {
        //        var obj = (LambdaToSqlAttribute)System.Attribute.GetCustomAttribute(pi, typeof(LambdaToSqlAttribute));
        //        if (obj != null)
        //        {
        //            if (obj.IsPrimaryKey)
        //            {
        //                list.Add(pi.Name);
        //            }
        //        }
        //    }
        //    return list;
        //}

        ///// <summary>
        ///// 获取标识列
        ///// </summary>
        ///// <typeparam name="T"></typeparam> 
        ///// <returns></returns>
        //public static List<string> GetIdentity<T>() where T : class, new()
        //{
        //    var properties = (new T()).GetType().GetProperties();
        //    var list = GetIdentity(properties);
        //    return list;
        //}

        ///// <summary>
        ///// 获取标识列
        ///// </summary>
        ///// <param name="properties"></param>
        ///// <returns></returns>
        //public static List<string> GetIdentity(PropertyInfo[] properties)
        //{
        //    var list = new List<string>();
        //    foreach (PropertyInfo pi in properties)
        //    {
        //        var obj = (LambdaToSqlAttribute)System.Attribute.GetCustomAttribute(pi, typeof(LambdaToSqlAttribute));
        //        if (obj != null)
        //        {
        //            if (obj.IsIdentity)
        //            {
        //                list.Add(pi.Name);
        //            }
        //        }
        //    }
        //    return list;
        //}
    }
}
